package com.cxy.services;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cxy.dao.MessageDao;
import com.cxy.pojo.Message;
import com.cxy.pojo.User;


@Service
@Transactional
public class MessageServices {
	@Resource
	private MessageDao messageDao;
	@Transactional(readOnly=true)
	public List<Message> find(){
		return messageDao.findAll();
	}
	@Transactional(readOnly=true)
	public List<Message> find(String property,boolean isAsc){
		return messageDao.findAll(isAsc, property);
	}
	@Transactional(readOnly=true)
	public List<Message> findByProperty(String pram,String val,boolean isAsc,String property){
		return messageDao.findByProperty(pram, val,isAsc,property);
	}
	@Transactional(readOnly=true)
	public List<Message> findByProperty(String pram){
		return messageDao.findByProperty("flag",pram);
	}
	@Transactional(readOnly=true)
	public Message get(int id){
		return messageDao.findById(id);
	}
	public void del(int id){
		messageDao.del(id);
	}
	public void saveOrUpdate(Message message){
		messageDao.saveOrUpdate(message);
	}
	public void save(String flag,String now,String content,String type,User user){
		messageDao.getSession().flush();
		Message  m = new Message();
		m.setFlag(flag);
		m.setSendTime(now);
		m.setUser(user);
		m.setType(type);
		m.setContent(content);
		saveOrUpdate(m);
	}
}
